/**
  * Testing OpenVG image filtering with built-in gaussian blur 
  *
  */

#include "game.h"
#include <qDebug>

// for readability, the screen and texture sizes are hard-coded
const float SCREEN_WIDTH=640.0f;
const float SCREEN_HEIGHT=360.0f;

// image resources
VGImage blurred;
VGImage image;

/** walltime */
float t;

float blurX=4.0f, blurY=4.0f;

void game_init()
{
}

void game_destroy()
{
}

void game_prepare()
{
    image = loadVGImage("images/koski.jpg");
    blurred = vgCreateImage(VG_lRGBA_8888, SCREEN_WIDTH, SCREEN_HEIGHT, VG_IMAGE_QUALITY_NONANTIALIASED);
}

void game_release()
{
    vgDestroyImage(blurred); blurred=VG_INVALID_HANDLE;
    vgDestroyImage(image); image=VG_INVALID_HANDLE;
}

void game_update(float walltime)
{
    t=walltime;
}

void game_render()
{
    // clear background using black
    VGfloat color[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
    vgSetfv( VG_CLEAR_COLOR, 4, color );
    vgClear( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);

    vgGaussianBlur(blurred, image, blurX, blurY, VG_TILE_PAD);

    vgSeti(VG_MATRIX_MODE, VG_MATRIX_IMAGE_USER_TO_SURFACE);
    vgLoadIdentity();
    vgTranslate(0,SCREEN_HEIGHT);
    vgScale(1,-1);

    vgDrawImage(blurred);

}

void game_event(int type, float x, float y, float z)
{
    blurX = x*16.0f/SCREEN_WIDTH;
    blurY = y*16.0f/SCREEN_HEIGHT;

    qDebug("blur %f, %f", blurX, blurY);
}
